package com.qf.fmall.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall.user.entity.UserAddr;
import com.qf.fmall.user.service.IUserAddrService;
import com.qf.fmall.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author djl
 * @since 2024-04-29
 */
@CrossOrigin
@RestController
@RequestMapping("/useraddr")
@Slf4j
public class UserAddrController {

    @Autowired
    private IUserAddrService userAddrService;

    @GetMapping("/list")
    public ResultVo list(@RequestParam("userId") Integer userId){

        //1. 打印日志
        log.info("收到的参数为,userId={}",userId);

        //2. 校验参数
        if (userId==null||userId<=0){
            throw new RuntimeException("userId参数非法");
        }

        //3. 调用service方法
        List<UserAddr> data =
                userAddrService.list(new QueryWrapper<UserAddr>().eq("user_id",userId));

        //4. 返回json
        return new ResultVo(10000, "success", data);
    }

}
